
import config
from informationMap import *
from proxyCanvas import Canvas

def test0(fontdir=".", outfile="/tmp/out.html"):
    c = Canvas()
    #c.addFont("propell", fontdir+"/propell.bdf")
    R = RelationBox("box1", c, config.Configuration())
    R.addAttribute("FirstAttrIsVeryLong", True)
    R.addAttribute("X", False)
    R.addAttribute("Y", False)
    R.addAttribute("wiggy", False)
    R.addAttribute("Z", True)
    R.addLinkage("wiggy", 2422)
    R.addLinkage("Z", 2432, mandatory=False)
    R.addLinkage("FirstAttrIsVeryLong", 2412, mandatory=False, onto=True)
    R.addLinkage("X", 2332, mandatory=False, oneToOne=True)
    R.anchored = True
    R.anchorY = -1900
    R.geometry()
    R.position(2020,-2220)
    R.draw()
    c.dumpTestHtml(outfile)
    print "test output to", outfile
"""
def test1(fontdir=".", outfile="/tmp/out1.html"):
    from skimpyGimpy import canvas
    c = canvas.Canvas()
    cfg = config.Configuration()
    c.addFont("propell", fontdir+"/propell.bdf")
    R = RelationBox("box1", c, cfg)
    R.addAttribute("FirstAttrIsVeryLong", True)
    R.addAttribute("X", False)
    R.addAttribute("Y", False)
    R.addAttribute("wiggy", False)
    R.addAttribute("Z", True)
    L = LayoutGrid()
    L.addBox(R, 0,0)
    L.connect("box1", "X", "box1")
    L.draw(c, cfg)
    c.dumpToPNG(outfile)
    print "test output to", outfile

def test2(fontdir=".", outfile="/tmp/out1.html"):
    from skimpyGimpy import canvas
    c = canvas.Canvas()
    cfg = config.Configuration()
    c.addFont("propell", fontdir+"/propell.bdf")
    L = LayoutGrid()

    R = RelationBox("box1", c, cfg)
    R.addAttribute("FirstAttrIsVeryLong", True)
    R.addAttribute("X", False)
    R.addAttribute("Y", False)
    R.addAttribute("wiggy", False)
    R.addAttribute("Z", True)
    L.addBox(R, 0,0)

    R = RelationBox("box2", c, cfg)
    R.addAttribute("AttrIsVeryLong", True)
    R.addAttribute("X", False)
    R.addAttribute("Y", False)
    R.addAttribute("wiggy", False)
    R.addAttribute("Z", True)
    L.addBox(R, 0,1)

    L.connect("box1", "X", "box2")
    L.draw(c, cfg)
    c.dumpToPNG(outfile)
    print "test output to", outfile

def test3(fontdir=".", outfile="/tmp/out1.html"):
    from skimpyGimpy import canvas
    c = canvas.Canvas()
    cfg = config.Configuration()
    c.addFont("propell", fontdir+"/propell.bdf")
    L = LayoutGrid()

    R = RelationBox("box1", c, cfg)
    R.addAttribute("FirstAttrIsVeryLong", True)
    R.addAttribute("X", False)
    R.addAttribute("Y", False)
    R.addAttribute("wiggy", False)
    R.addAttribute("Z", True)
    L.addBox(R, 0,0)

    R = RelationBox("box2", c, cfg)
    R.addAttribute("AttrIsVeryLong", True)
    R.addAttribute("X", False)
    R.addAttribute("Y", False)
    R.addAttribute("wiggy", False)
    R.addAttribute("Z", True)
    L.addBox(R, 1,0)

    L.connect("box1", "X", "box2", mandatory=False)
    L.connect("box2", "Y", "box1", onto=True, oneToOne=True)
    L.draw(c, cfg)
    c.dumpToPNG(outfile)
    print "test output to", outfile

def test4(fontdir=".", outfile="/tmp/meta.html"):
    from skimpyGimpy import canvas
    c = canvas.Canvas()
    cfg = config.Configuration()
    c.addFont("propell", fontdir+"/propell.bdf")
    L = LayoutGrid()

    R = RelationBox("Attribute", c, cfg)
    R.addAttribute("aName", True)
    R.addAttribute("aType", False)
    R.addAttribute("isKey", False)
    R.addAttribute("optional", False)
    R.addAttribute("describes", True)
    L.addBox(R, 0,0)

    R = RelationBox("Mapping", c, cfg)
    R.addAttribute("mName", True)
    R.addAttribute("isRoot", False)
    L.addBox(R, 1,1)

    R = RelationBox("Role", c, cfg)
    R.addAttribute("rName", True)
    R.addAttribute("isRoot", False)
    R.addAttribute("pMin", False)
    R.addAttribute("pMax", False)
    R.addAttribute("defaultPath", False)
    R.addAttribute("owner", True)
    R.addAttribute("defines", True)
    L.addBox(R, 2,0)

    L.connect("Attribute", "describes", "Mapping")
    L.connect("Role", "defines", "Mapping")
    L.connect("Role", "owner", "Mapping")
    L.draw(c, cfg)
    c.dumpToPNG(outfile)
    print "test output to", outfile

def testShift(fontdir=".", outfile="/tmp/shift.html"):
    from skimpyGimpy import canvas
    c = canvas.Canvas()
    cfg = config.Configuration()
    c.addFont("propell", fontdir+"/propell.bdf")
    L = LayoutGrid()
    A = RelationBox("A", c, cfg)
    B = RelationBox("B", c, cfg)
    C = RelationBox("C", c, cfg)
    D = RelationBox("D", c, cfg)
    A.addAttribute("X", True)
    B.addAttribute("X", True)
    C.addAttribute("X", True)
    D.addAttribute("X", True)
    L.addBox(A, 0,1)
    L.addBox(B, 0,2)
    L.addBox(C, 0,3)
    L.addBox(D, 0,4)
    L.connect("A", "X", "B")
    L.connect("C", "X", "D")
    L.draw(c, cfg)
    c.dumpToPNG(outfile)
    print "test output to", outfile

def testShift1(fontdir=".", outfile="/tmp/shift1.html"):
    from skimpyGimpy import canvas
    c = canvas.Canvas()
    cfg = config.Configuration()
    c.addFont("propell", fontdir+"/propell.bdf")
    L = LayoutGrid()
    A = RelationBox("A", c, cfg)
    B = RelationBox("B", c, cfg)
    C = RelationBox("C", c, cfg)
    D = RelationBox("D", c, cfg)
    A.addAttribute("X", True)
    B.addAttribute("X", True)
    C.addAttribute("X", True)
    D.addAttribute("X", True)
    L.addBox(A, 1,0)
    L.addBox(B, 2,0)
    L.addBox(C, 3,0)
    L.addBox(D, 4,0)
    L.connect("A", "X", "B")
    L.connect("C", "X", "D")
    L.draw(c, cfg)
    c.dumpToPNG(outfile)
    print "test output to", outfile

def test5(fontdir=".", outfile="/tmp/meta.html"):
    from skimpyGimpy import canvas
    c = canvas.Canvas()
    cfg = config.Configuration()
    c.addFont("propell", fontdir+"/propell.bdf")
    L = LayoutGrid()
    connectCollector = {}
    for info in [
        ("Person", 0, 0, ["id"], [], {}),
        ("Group", 2, 0, ["name", "creator"], [], {"creator":"Person"}),
        ("Joined", 1, 0, ["member","inGroup"], [], {"member":"Person", "inGroup":"Group"}), 
        ("CanSit", 1, 1, ["allowed","forExam"], [], {"allowed":"Group", "forExam":"Exam"}), 
        ("ExamTemplate", 0, 2, ["eid"], ["creator"], {"creator":"Person"}), 
        ("Exam", 1, 2, ["iid"], ["setter","derivedFrom"], {"setter":"Person", "derivedFrom":"ExamTemplate"}), 
        ("Sitting", 2, 1, ["sid"], ["sitter", "duplicates"], {"sitter":"Person", "duplicates":"Exam"}), 
        ("Includes", 2,2, ["examT", "questionT"], [], {"examT":"ExamTemplate", "questionT":"QuestionTemplate"}),
        ("QuestionTemplate", 0,3, ["Qtid"], ["creator"], {"creator":"Person"}),
        ("Question", 1,3, ["qid"], ["Container", "CopyOf"], {"Container":"Exam","CopyOf":"QuestionTemplate"}),
        ("Answer", 2,3, ["forQuestion", "inSitting"], [], {"forQuestion":"Question", "inSitting":"Sitting"}),
        ("Grade", 3,3, ["forAnswer"], ["grader"], {"forAnswer":"Answer", "grader":"Person"}),
        ("Rubric", 1,4, ["rid"], ["forQuestion"], {"forQuestion":"Question"}),
        ("Uses", 2,4, ["rubric", "grade"], [], {"rubric": "Rubric", "grade":"Grade"}),
        ]:
        print info
        (name,i,j,keys,others,connections) = info
        R = RelationBox(name, c, cfg)
        for k in keys:
            R.addAttribute(k, True)
        for o in others:
            R.addAttribute(o, False)
        L.addBox(R, i, j)
        for (fromatt,tobox) in connections.items():
            connectCollector[ (name, fromatt, tobox) ] = 1
    for (sourceBox, sourceAtt, destBox) in connectCollector.keys():
        L.connect(sourceBox, sourceAtt, destBox)
    L.draw(c, cfg)
    c.dumpToPNG(outfile)
    print "test output to", outfile    

def test6(fontdir=".", outfile="/tmp/meta.html"):
    from skimpyGimpy import canvas
    c = canvas.Canvas()
    cfg = config.Configuration()
    c.addFont("propell", fontdir+"/propell.bdf")
    L = LayoutGrid()
    connectCollector = {}
    for info in [
        ("Person", 0, 0, ["id"], [], {}),
        ("Group", 1, 0, ["name", "creator"], [], {"creator":"Person"}),
        ("Joined", 2, 0, ["member","inGroup"], [], {"member":"Person", "inGroup":"Group"}), 
        ("CanSit", 1, 1, ["allowed","forExam"], [], {"allowed":"Group", "forExam":"Exam"}), 
        ("ExamTemplate", 0, 2, ["eid"], ["creator"], {"creator":"Person"}), 
        ("Exam", 1, 2, ["iid"], ["setter","derivedFrom"], {"setter":"Person", "derivedFrom":"ExamTemplate"}), 
        ("Sitting", 2, 1, ["sid"], ["sitter", "duplicates"], {"sitter":"Person", "duplicates":"Exam"}), 
        ("Includes", 2,2, ["examT", "questionT"], [], {"examT":"ExamTemplate", "questionT":"QuestionTemplate"}),
        ("QuestionTemplate", 0,3, ["Qtid"], ["creator"], {"creator":"Person"}),
        ("Question", 1,3, ["qid"], ["Container", "CopyOf"], {"Container":"Exam","CopyOf":"QuestionTemplate"}),
        ("Answer", 2,3, ["forQuestion", "inSitting"], [], {"forQuestion":"Question", "inSitting":"Sitting"}),
        ("Grade", 3,3, ["forAnswer"], ["grader"], {"forAnswer":"Answer", "grader":"Person"}),
        ("Rubric", 1,4, ["rid"], ["forQuestion"], {"forQuestion":"Question"}),
        ("Uses", 2,4, ["rubric", "grade"], [], {"rubric": "Rubric", "grade":"Grade"}),
        ]:
        print info
        (name,i,j,keys,others,connections) = info
        R = RelationBox(name, c, cfg)
        for k in keys:
            R.addAttribute(k, True)
        for o in others:
            R.addAttribute(o, False)
        L.addBox(R, j, i)
        for (fromatt,tobox) in connections.items():
            connectCollector[ (name, fromatt, tobox) ] = 1
    for (sourceBox, sourceAtt, destBox) in connectCollector.keys():
        L.connect(sourceBox, sourceAtt, destBox)
    L.draw(c, cfg)
    c.dumpToPNG(outfile)
    print "test output to", outfile    

def test7(fontdir=".", outfile="/tmp/meta.html"):
    from skimpyGimpy import canvas
    c = canvas.Canvas()
    cfg = config.Configuration()
    c.addFont("propell", fontdir+"/propell.bdf")
    L = LayoutGrid()
    connectCollector = {}
    for info in [
        ("Person", 0, 0, ["id"], [], {}),
        ("Group", 0, 1, ["name", "creator"], [], {"creator":"Person"}),
        ("Joined", 0, 2, ["member","inGroup"], [], {"member":"Person", "inGroup":"Group"}), 
        ("CanSit", 0, 3, ["allowed","forExam"], [], {"allowed":"Group", "forExam":"Exam"}), 
        ("ExamTemplate", 0, 4, ["eid"], ["creator"], {"creator":"Person"}), 
        ("Exam", 0,5, ["iid"], ["setter","derivedFrom"], {"setter":"Person", "derivedFrom":"ExamTemplate"}), 
        ("Sitting", 0,6, ["sid"], ["sitter", "duplicates"], {"sitter":"Person", "duplicates":"Exam"}), 
        ("Includes", 0,7, ["examT", "questionT"], [], {"examT":"ExamTemplate", "questionT":"QuestionTemplate"}),
        ("QuestionTemplate", 0,8, ["Qtid"], ["creator"], {"creator":"Person"}),
        ("Question", 0,9, ["qid"], ["Container", "CopyOf"], {"Container":"Exam","CopyOf":"QuestionTemplate"}),
        ("Answer", 0,10, ["forQuestion", "inSitting"], [], {"forQuestion":"Question", "inSitting":"Sitting"}),
        ("Grade", 0,11, ["forAnswer"], ["grader"], {"forAnswer":"Answer", "grader":"Person"}),
        ("Rubric", 0,12, ["rid"], ["forQuestion"], {"forQuestion":"Question"}),
        ("Uses", 0,13, ["rubric", "grade"], [], {"rubric": "Rubric", "grade":"Grade"}),
        ]:
        print info
        (name,i,j,keys,others,connections) = info
        R = RelationBox(name, c, cfg)
        for k in keys:
            R.addAttribute(k, True)
        for o in others:
            R.addAttribute(o, False)
        L.addBox(R, j, i)
        for (fromatt,tobox) in connections.items():
            connectCollector[ (name, fromatt, tobox) ] = 1
    for (sourceBox, sourceAtt, destBox) in connectCollector.keys():
        L.connect(sourceBox, sourceAtt, destBox)
    L.draw(c, cfg)
    c.dumpToPNG(outfile)
    print "test output to", outfile    
"""
def test8(fontdir=".", outfile="/tmp/meta.html"):
    c = Canvas()
    cfg = config.Configuration()
    #c.addFont("Courier", fontdir+"/propell.bdf")
    L = LayoutGrid()
    connectCollector = {}
    for info in [
        ("Person", 0, 0, ["id"], [], {}),
        ("Group", 0, 1, ["name", "creator"], [], {"creator":"Person"}),
        ("Joined", 0, 2, ["member","inGroup"], [], {"member":"Person", "inGroup":"Group"}), 
        ("CanSit", 0, 3, ["allowed","forExam"], [], {"allowed":"Group", "forExam":"Exam"}), 
        ("ExamTemplate", 1, 1, ["eid"], ["creator"], {"creator":"Person"}), 
        ("Exam", 1,2, ["iid"], ["setter","derivedFrom"], {"setter":"Person", "derivedFrom":"ExamTemplate"}), 
        ("Sitting", 1,3, ["sid"], ["sitter", "duplicates"], {"sitter":"Person", "duplicates":"Exam"}), 
        ("Includes", 2,0, ["examT", "questionT"], [], {"examT":"ExamTemplate", "questionT":"QuestionTemplate"}),
        ("QuestionTemplate", 2,1, ["Qtid"], ["creator"], {"creator":"Person"}),
        ("Question", 2,2, ["qid"], ["Container", "CopyOf"], {"Container":"Exam","CopyOf":"QuestionTemplate"}),
        ("Answer", 3,0, ["forQuestion", "inSitting"], [], {"forQuestion":"Question", "inSitting":"Sitting"}),
        ("Grade", 3,1, ["forAnswer"], ["grader"], {"forAnswer":"Answer", "grader":"Person"}),
        ("Rubric", 3,2, ["rid"], ["forQuestion"], {"forQuestion":"Question"}),
        ("Uses", 3,3, ["rubric", "grade"], [], {"rubric": "Rubric", "grade":"Grade"}),
        ]:
        print info
        (name,i,j,keys,others,connections) = info
        R = RelationBox(name, c, cfg)
        for k in keys:
            R.addAttribute(k, True)
        for o in others:
            R.addAttribute(o, False)
        L.addBox(R, j, i)
        for (fromatt,tobox) in connections.items():
            connectCollector[ (name, fromatt, tobox) ] = 1
    for (sourceBox, sourceAtt, destBox) in connectCollector.keys():
        L.connect(sourceBox, sourceAtt, destBox)
    L.draw(c, cfg)
    c.dumpTestHtml(outfile)
    print "test output to", outfile    

if __name__=="__main__":
    test8()

